using System;
using System.Reflection;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Globalization;
using System.Drawing;
using System.Drawing.Design;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PickGold.Controls
{
	[ValidationProperty("SelectedItem")]
	[SupportsEventValidation]
	[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	[AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	[Designer(typeof(DatePickerDropDownListDesigner))]
	[ToolboxData("<{0}:DatePickerDropDownList runat=\"server\"></{0}:DatePicker>")]
	[DefaultEvent("SelectedIndexChanged"), ParseChildren(true, "Items"), ControlValueProperty("SelectedValue")]
	[DataBindingHandler("System.Web.UI.Design.WebControls.ListControlDataBindingHandler, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
	[AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	[AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
	public class DatePickerDropDownList : DataBoundControl, IEditableTextControl, ITextControl, IPostBackDataHandler
	{
		#region listControl v

		private bool _stateLoaded;
		private int cachedSelectedIndex = -1;
		private ArrayList cachedSelectedIndices;
		private string cachedSelectedValue;
		private static readonly object EventSelectedIndexChanged = new object();
		private static readonly object EventTextChanged = new object();
		private DatePickerListItemCollection items;

		#endregion

		#region listControl

		//[WebCategory("Action")]
		//[WebSysDescription("ListControl_OnSelectedIndexChanged")]
		public event EventHandler SelectedIndexChanged
		{
			add
			{
				base.Events.AddHandler(EventSelectedIndexChanged, value);
			}
			remove
			{
				base.Events.RemoveHandler(EventSelectedIndexChanged, value);
			}
		}

		//[WebCategory("Action")]
		//[WebSysDescription("ListControl_TextChanged")]
		public event EventHandler TextChanged
		{
			add
			{
				base.Events.AddHandler(EventTextChanged, value);
			}
			remove
			{
				base.Events.RemoveHandler(EventTextChanged, value);
			}
		}

		/*
		protected override void AddAttributesToRender(HtmlTextWriter writer)
		{
			if (this.Page != null)
			{
				this.Page.VerifyRenderingInServerForm(this);
			}
			if (this.IsMultiSelectInternal)
			{
				writer.AddAttribute(HtmlTextWriterAttribute.Multiple, "multiple");
			}
			if ((this.AutoPostBack && (this.Page != null)) && this.Page.ClientSupportsJavaScript)
			{
				string str = null;
				if (base.HasAttributes)
				{
					str = base.Attributes["onchange"];
					if (str != null)
					{
						str = Util.EnsureEndWithSemiColon(str);
						base.Attributes.Remove("onchange");
					}
				}
				PostBackOptions options = new PostBackOptions(this, string.Empty);
				if (this.CausesValidation)
				{
					options.PerformValidation = true;
					options.ValidationGroup = this.ValidationGroup;
				}
				if (this.Page.Form != null)
				{
					options.AutoPostBack = true;
				}
				str = Util.MergeScript(str, this.Page.ClientScript.GetPostBackEventReference(options, true));
				writer.AddAttribute(HtmlTextWriterAttribute.Onchange, str);
				if (base.EnableLegacyRendering)
				{
					writer.AddAttribute("language", "javascript", false);
				}
			}
			if (this.Enabled && !base.IsEnabled)
			{
				writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");
			}
			base.AddAttributesToRender(writer);
		}
		*/

		public virtual void ClearSelection()
		{
			for (int i = 0; i < this.Items.Count; i++)
			{
				this.Items[i].Selected = false;
			}
		}

		protected override void LoadViewState(object savedState)
		{
			if (savedState != null)
			{
				Triplet triplet = (Triplet)savedState;
				base.LoadViewState(triplet.First);
				this.Items.LoadViewState(triplet.Second);
				ArrayList third = triplet.Third as ArrayList;
				if (third != null)
				{
					this.SelectInternal(third);
				}
			}
			else
			{
				base.LoadViewState(null);
			}
			this._stateLoaded = true;
		}

		protected override void OnDataBinding(EventArgs e)
		{
			base.OnDataBinding(e);
			object o = this.GetData();
			MethodInfo mi = o.GetType().GetMethod("ExecuteSelect", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(DataSourceSelectArguments) }, null);
			//IEnumerable data = this.GetData().ExecuteSelect(DataSourceSelectArguments.Empty);
			this.PerformDataBinding(mi.Invoke(o, new object[] { DataSourceSelectArguments.Empty }) as IEnumerable);//data// = this.GetData()
		}

		/*
		protected internal override void OnPreRender(EventArgs e)
		{
			base.OnPreRender(e);
			if ((this.Page != null) && base.IsEnabled)
			{
				if (this.AutoPostBack)
				{
					this.Page.RegisterPostBackScript();
					this.Page.RegisterFocusScript();
					if (this.CausesValidation && (this.Page.GetValidators(this.ValidationGroup).Count > 0))
					{
						this.Page.RegisterWebFormsScript();
					}
				}
				if (!this.SaveSelectedIndicesViewState)
				{
					this.Page.RegisterEnabledControl(this);
				}
			}
		}
		*/

		protected virtual void OnSelectedIndexChanged(EventArgs e)
		{
			EventHandler handler = (EventHandler)base.Events[EventSelectedIndexChanged];
			if (handler != null)
			{
				handler(this, e);
			}
			this.OnTextChanged(e);
		}

		protected virtual void OnTextChanged(EventArgs e)
		{
			EventHandler handler = (EventHandler)base.Events[EventTextChanged];
			if (handler != null)
			{
				handler(this, e);
			}
		}

		/*
		protected internal override void PerformDataBinding(IEnumerable dataSource)
		{
			base.PerformDataBinding(dataSource);
			if (dataSource != null)
			{
				bool flag = false;
				bool flag2 = false;
				string dataTextField = this.DataTextField;
				string dataValueField = this.DataValueField;
				string dataTextFormatString = this.DataTextFormatString;
				if (!this.AppendDataBoundItems)
				{
					this.Items.Clear();
				}
				ICollection is2 = dataSource as ICollection;
				if (is2 != null)
				{
					this.Items.Capacity = is2.Count + this.Items.Count;
				}
				if ((dataTextField.Length != 0) || (dataValueField.Length != 0))
				{
					flag = true;
				}
				if (dataTextFormatString.Length != 0)
				{
					flag2 = true;
				}
				foreach (object obj2 in dataSource)
				{
					DatePickerListItem item = new DatePickerListItem();
					if (flag)
					{
						if (dataTextField.Length > 0)
						{
							item.Text = DataBinder.GetPropertyValue(obj2, dataTextField, dataTextFormatString);
						}
						if (dataValueField.Length > 0)
						{
							item.Value = DataBinder.GetPropertyValue(obj2, dataValueField, null);
						}
					}
					else
					{
						if (flag2)
						{
							item.Text = string.Format(CultureInfo.CurrentCulture, dataTextFormatString, new object[] { obj2 });
						}
						else
						{
							item.Text = obj2.ToString();
						}
						item.Value = obj2.ToString();
					}
					this.Items.Add(item);
				}
			}
			if (this.cachedSelectedValue != null)
			{
				int num = -1;
				num = this.Items.FindByValueInternal(this.cachedSelectedValue, true);
				if (-1 == num)
				{
					throw new ArgumentOutOfRangeException("value", System.Web.SR.GetString("ListControl_SelectionOutOfRange", new object[] { this.ID, "SelectedValue" }));
				}
				if ((this.cachedSelectedIndex != -1) && (this.cachedSelectedIndex != num))
				{
					throw new ArgumentException(System.Web.SR.GetString("Attributes_mutually_exclusive", new object[] { "SelectedIndex", "SelectedValue" }));
				}
				this.SelectedIndex = num;
				this.cachedSelectedValue = null;
				this.cachedSelectedIndex = -1;
			}
			else if (this.cachedSelectedIndex != -1)
			{
				this.SelectedIndex = this.cachedSelectedIndex;
				this.cachedSelectedIndex = -1;
			}
		}
		*/

		protected override void PerformSelect()
		{
			this.OnDataBinding(EventArgs.Empty);
			base.RequiresDataBinding = false;
			base.MarkAsDataBound();
			this.OnDataBound(EventArgs.Empty);
		}

		/*
		protected internal override void RenderContents(HtmlTextWriter writer)
		{
			DatePickerListItemCollection items = this.Items;
			int count = items.Count;
			if (count > 0)
			{
				bool flag = false;
				for (int i = 0; i < count; i++)
				{
					DatePickerListItem item = items[i];
					if (item.Enabled)
					{
						writer.WriteBeginTag("option");
						if (item.Selected)
						{
							if (flag)
							{
								this.VerifyMultiSelect();
							}
							flag = true;
							writer.WriteAttribute("selected", "selected");
						}
						writer.WriteAttribute("value", item.Value, true);
						if (item.HasAttributes)
						{
							item.Attributes.Render(writer);
						}
						if (this.Page != null)
						{
							this.Page.ClientScript.RegisterForEventValidation(this.UniqueID, item.Value);
						}
						writer.Write('>');
						HttpUtility.HtmlEncode(item.Text, writer);
						writer.WriteEndTag("option");
						writer.WriteLine();
					}
				}
			}
		}
		*/

		protected override object SaveViewState()
		{
			object x = base.SaveViewState();
			object y = this.Items.SaveViewState();
			object z = null;
			if (this.SaveSelectedIndicesViewState)
			{
				z = this.SelectedIndicesInternal;
			}
			if (((z == null) && (y == null)) && (x == null))
			{
				return null;
			}
			return new Triplet(x, y, z);
		}

		internal void SelectInternal(ArrayList selectedIndices)
		{
			this.ClearSelection();
			for (int i = 0; i < selectedIndices.Count; i++)
			{
				int num2 = (int)selectedIndices[i];
				if ((num2 >= 0) && (num2 < this.Items.Count))
				{
					this.Items[num2].Selected = true;
				}
			}
			this.cachedSelectedIndices = selectedIndices;
		}

		protected void SetPostDataSelection(int selectedIndex)
		{
			if ((this.Items.Count != 0) && (selectedIndex < this.Items.Count))
			{
				this.ClearSelection();
				if (selectedIndex >= 0)
				{
					this.Items[selectedIndex].Selected = true;
				}
			}
		}

		protected override void TrackViewState()
		{
			base.TrackViewState();
			this.Items.TrackViewState();
		}

		/*
		protected internal virtual void VerifyMultiSelect()
		{
			if (!this.IsMultiSelectInternal)
			{
				throw new HttpException(System.Web.SR.GetString("Cant_Multiselect_In_Single_Mode"));
			}
		}
		*/

		//[WebCategory("Behavior"), Themeable(false)]
		//[WebSysDescription("ListControl_AppendDataBoundItems")]
		[DefaultValue(false)]
		public virtual bool AppendDataBoundItems
		{
			get
			{
				object obj2 = this.ViewState["AppendDataBoundItems"];
				return ((obj2 != null) && ((bool)obj2));
			}
			set
			{
				this.ViewState["AppendDataBoundItems"] = value;
				if (base.Initialized)
				{
					base.RequiresDataBinding = true;
				}
			}
		}

		//[WebCategory("Behavior")]
		//[WebSysDescription("ListControl_AutoPostBack")]
		[DefaultValue(false)]
		[Themeable(false)]
		public virtual bool AutoPostBack
		{
			get
			{
				object obj2 = this.ViewState["AutoPostBack"];
				return ((obj2 != null) && ((bool)obj2));
			}
			set
			{
				this.ViewState["AutoPostBack"] = value;
			}
		}

		//[WebCategory("Behavior")]
		//[WebSysDescription("AutoPostBackControl_CausesValidation")]
		[DefaultValue(false)]
		[Themeable(false)]
		public virtual bool CausesValidation
		{
			get
			{
				object obj2 = this.ViewState["CausesValidation"];
				return ((obj2 != null) && ((bool)obj2));
			}
			set
			{
				this.ViewState["CausesValidation"] = value;
			}
		}

		//[WebCategory("Data")]
		//[WebSysDescription("ListControl_DataTextField")]
		[Themeable(false)]
		[DefaultValue("")]
		public virtual string DataTextField
		{
			get
			{
				object obj2 = this.ViewState["DataTextField"];
				if (obj2 != null)
				{
					return (string)obj2;
				}
				return string.Empty;
			}
			set
			{
				this.ViewState["DataTextField"] = value;
				if (base.Initialized)
				{
					base.RequiresDataBinding = true;
				}
			}
		}

		//[WebCategory("Data")]
		//[WebSysDescription("ListControl_DataTextFormatString")]
		[DefaultValue("")]
		[Themeable(false)]
		public virtual string DataTextFormatString
		{
			get
			{
				object obj2 = this.ViewState["DataTextFormatString"];
				if (obj2 != null)
				{
					return (string)obj2;
				}
				return string.Empty;
			}
			set
			{
				this.ViewState["DataTextFormatString"] = value;
				if (base.Initialized)
				{
					base.RequiresDataBinding = true;
				}
			}
		}

		//[WebCategory("Data")]
		//[WebSysDescription("ListControl_DataValueField")]
		[DefaultValue("")]
		[Themeable(false)]
		public virtual string DataValueField
		{
			get
			{
				object obj2 = this.ViewState["DataValueField"];
				if (obj2 != null)
				{
					return (string)obj2;
				}
				return string.Empty;
			}
			set
			{
				this.ViewState["DataValueField"] = value;
				if (base.Initialized)
				{
					base.RequiresDataBinding = true;
				}
			}
		}

		/*
		internal virtual bool IsMultiSelectInternal
		{
			get
			{
				return false;
			}
		}
		*/

		//[WebCategory("Default")]
		//[WebSysDescription("ListControl_Items")]
		[DefaultValue((string)null)]
		[MergableProperty(false)]
		[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
		[Editor("System.Web.UI.Design.WebControls.ListItemsCollectionEditor,System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
		public virtual DatePickerListItemCollection Items
		{
			get
			{
				if (this.items == null)
				{
					this.items = new DatePickerListItemCollection();
					if (base.IsTrackingViewState)
					{
						this.items.TrackViewState();
					}
				}
				return this.items;
			}
		}

		internal bool SaveSelectedIndicesViewState
		{
			get
			{
				PropertyInfo pi = this.Page.GetType().GetProperty("ClientSupportsJavaScript", BindingFlags.NonPublic | BindingFlags.Instance, null, typeof(bool), new Type[0], null);
				if ((((base.Events[EventSelectedIndexChanged] != null) || (base.Events[EventTextChanged] != null)) || (!base.IsEnabled || !this.Visible)) || ((this.AutoPostBack && (this.Page != null)) && !((bool)pi.GetValue(this.Page, null))))//this.Page.ClientSupportsJavaScript
				{
					return true;
				}
				foreach (DatePickerListItem item in this.Items)
				{
					if (!item.Enabled)
					{
						return true;
					}
				}
				Type type = base.GetType();
				return (((type != typeof(DropDownList)) && (type != typeof(ListBox))) && ((type != typeof(CheckBoxList)) && (type != typeof(RadioButtonList))));
			}
		}

		/*
		//[WebCategory("Behavior")]
		//[WebSysDescription("WebControl_SelectedIndex")]
		[Bindable(true)]
		[DefaultValue(0)]
		[Themeable(false)]
		[Browsable(false)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public virtual int SelectedIndex
		{
			get
			{
				for (int i = 0; i < this.Items.Count; i++)
				{
					if (this.Items[i].Selected)
					{
						return i;
					}
				}
				return -1;
			}
			set
			{
				if (value < -1)
				{
					if (this.Items.Count != 0)
					{
						throw new ArgumentOutOfRangeException("value", System.Web.SR.GetString("ListControl_SelectionOutOfRange", new object[] { this.ID, "SelectedIndex" }));
					}
					value = -1;
				}
				if (((this.Items.Count != 0) && (value < this.Items.Count)) || (value == -1))
				{
					this.ClearSelection();
					if (value >= 0)
					{
						this.Items[value].Selected = true;
					}
				}
				else if (this._stateLoaded)
				{
					throw new ArgumentOutOfRangeException("value", System.Web.SR.GetString("ListControl_SelectionOutOfRange", new object[] { this.ID, "SelectedIndex" }));
				}
				this.cachedSelectedIndex = value;
			}
		}
		*/

		/*
		internal virtual ArrayList SelectedIndicesInternal
		{
			get
			{
				this.cachedSelectedIndices = new ArrayList(3);
				for (int i = 0; i < this.Items.Count; i++)
				{
					if (this.Items[i].Selected)
					{
						this.cachedSelectedIndices.Add(i);
					}
				}
				return this.cachedSelectedIndices;
			}
		}
		*/

		//[WebCategory("Behavior")]
		//[WebSysDescription("ListControl_SelectedItem")]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		[Browsable(false)]
		[DefaultValue((string)null)]
		public virtual DatePickerListItem SelectedItem
		{
			get
			{
				int selectedIndex = this.SelectedIndex;
				if (selectedIndex >= 0)
				{
					return this.Items[selectedIndex];
				}
				return null;
			}
		}

		//[WebCategory("Behavior")]
		//[WebSysDescription("ListControl_SelectedValue")]
		[Browsable(false)]
		[Bindable(true, BindingDirection.TwoWay)]
		[DefaultValue("")]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		[Themeable(false)]
		public virtual string SelectedValue
		{
			get
			{
				int selectedIndex = this.SelectedIndex;
				if (selectedIndex >= 0)
				{
					return this.Items[selectedIndex].Value;
				}
				return string.Empty;
			}
			set
			{
				if (this.Items.Count != 0)
				{
					if ((value == null) || (base.DesignMode && (value.Length == 0)))
					{
						this.ClearSelection();
						return;
					}
					DatePickerListItem item = this.Items.FindByValue(value);
					if ((((this.Page != null) && this.Page.IsPostBack) && this._stateLoaded) && (item == null))
					{
						//throw new ArgumentOutOfRangeException("value", System.Web.SR.GetString("ListControl_SelectionOutOfRange", new object[] { this.ID, "SelectedValue" }));
						throw new ArgumentOutOfRangeException("List Control Selection Out Of Range Selected Value");
					}
					if (item != null)
					{
						this.ClearSelection();
						item.Selected = true;
					}
				}
				this.cachedSelectedValue = value;
			}
		}

		protected override HtmlTextWriterTag TagKey
		{
			get
			{
				return HtmlTextWriterTag.Select;
			}
		}

		//[WebCategory("Behavior")]
		//[WebSysDescription("ListControl_Text")]
		[Browsable(false)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		[Themeable(false)]
		[DefaultValue("")]
		public virtual string Text
		{
			get
			{
				return this.SelectedValue;
			}
			set
			{
				this.SelectedValue = value;
			}
		}

		//[WebCategory("Behavior")]
		//[WebSysDescription("PostBackControl_ValidationGroup")]
		[DefaultValue("")]
		[Themeable(false)]
		public virtual string ValidationGroup
		{
			get
			{
				string str = (string)this.ViewState["ValidationGroup"];
				if (str != null)
				{
					return str;
				}
				return string.Empty;
			}
			set
			{
				this.ViewState["ValidationGroup"] = value;
			}
		}

		#endregion

		/************************************************************************************************************/

		protected override void AddAttributesToRender(HtmlTextWriter writer)
		{
			string uniqueID = this.UniqueID;
			if (uniqueID != null)
				writer.AddAttribute(HtmlTextWriterAttribute.Name, uniqueID);
			if (this.Page != null)
				this.Page.VerifyRenderingInServerForm(this);
			//if (this.IsMultiSelectInternal)
			//	writer.AddAttribute(HtmlTextWriterAttribute.Multiple, "multiple");
			PropertyInfo pi = this.Page.GetType().GetProperty("ClientSupportsJavaScript", BindingFlags.NonPublic | BindingFlags.Instance, null, typeof(bool), new Type[0], null);
			if ((this.AutoPostBack && (this.Page != null)) && ((bool)pi.GetValue(this.Page, null)))//this.Page.ClientSupportsJavaScript
			{
				string str = null;
				if (base.HasAttributes)
				{
					str = base.Attributes["onchange"];
					if (str != null)
					{
						str = Util.EnsureEndWithSemiColon(str);
						base.Attributes.Remove("onchange");
					}
				}
				PostBackOptions options = new PostBackOptions(this, string.Empty);
				if (this.CausesValidation)
				{
					options.PerformValidation = true;
					options.ValidationGroup = this.ValidationGroup;
				}
				if (this.Page.Form != null)
					options.AutoPostBack = true;
				str = Util.MergeScript(str, this.Page.ClientScript.GetPostBackEventReference(options, true));
				writer.AddAttribute(HtmlTextWriterAttribute.Onchange, str);
				pi = this.GetType().GetProperty("EnableLegacyRendering", BindingFlags.NonPublic | BindingFlags.Instance, null, typeof(bool), new Type[0], null);
				if (((bool)pi.GetValue(this, null)))//base.EnableLegacyRendering
					writer.AddAttribute("language", "javascript", false);
			}
			if (this.Enabled && !base.IsEnabled)
			{
				writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");
			}
			base.AddAttributesToRender(writer);
		}

		//[WebCategory("Behavior")]
		//[WebSysDescription("WebControl_SelectedIndex")]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		[Bindable(true)]
		[DefaultValue(0)]
		[Themeable(false)]
		[Browsable(false)]
		public virtual int SelectedIndex
		{
			get
			{
				int i;
				for (i = 0; i < this.Items.Count; i++)
				{
					if (this.Items[i].Selected)
						break;
				}
				if (i >= this.Items.Count)
				{
					if (this.Items.Count > 0)
					{
						this.Items[0].Selected = true;
						return 0;
					}

					return -1;
				}

				return i;
			}
			set
			{
				if (value < -1)
				{
					if (this.Items.Count != 0)
					{
						//throw new ArgumentOutOfRangeException("value", System.Web.SR.GetString("ListControl_SelectionOutOfRange", new object[] { this.ID, "SelectedIndex" }));
						throw new ArgumentOutOfRangeException("List Control Selection Out Of Range Selected Index");
					}
					value = -1;
				}
				if (((this.Items.Count != 0) && (value < this.Items.Count)) || (value == -1))
				{
					this.ClearSelection();
					if (value >= 0)
					{
						this.Items[value].Selected = true;
					}
				}
				else if (this._stateLoaded)
				{
					//throw new ArgumentOutOfRangeException("value", System.Web.SR.GetString("ListControl_SelectionOutOfRange", new object[] { this.ID, "SelectedIndex" }));
					throw new ArgumentOutOfRangeException("List Control Selection Out Of Range Selected Index");
				}
				this.cachedSelectedIndex = value;
			}
		}

		internal virtual ArrayList SelectedIndicesInternal
		{
			get
			{
				int i = this.SelectedIndex;
				this.cachedSelectedIndices = new ArrayList(3);
				for (i = 0; i < this.Items.Count; i++)
				{
					if (this.Items[i].Selected)
						this.cachedSelectedIndices.Add(i);
				}
				return this.cachedSelectedIndices;
			}
		}

		protected override void OnPreRender(EventArgs e)
		{
			MethodInfo mi;
			base.OnPreRender(e);
			if ((this.Page != null) && base.IsEnabled)
			{
				if (this.AutoPostBack)
				{
					mi = this.Page.GetType().GetMethod("RegisterPostBackScript", BindingFlags.NonPublic | BindingFlags.Instance);
					mi.Invoke(this.Page, null);
					//this.Page.RegisterPostBackScript();
					mi = this.Page.GetType().GetMethod("RegisterFocusScript", BindingFlags.NonPublic | BindingFlags.Instance);
					mi.Invoke(this.Page, null);
					//this.Page.RegisterFocusScript();
					if (this.CausesValidation && (this.Page.GetValidators(this.ValidationGroup).Count > 0))
					{
						mi = this.Page.GetType().GetMethod("RegisterWebFormsScript", BindingFlags.NonPublic | BindingFlags.Instance);
						mi.Invoke(this.Page, null);
						//this.Page.RegisterWebFormsScript();
					}
				}
				if (!this.SaveSelectedIndicesViewState)
				{
					mi = this.Page.GetType().GetMethod("RegisterEnabledControl", BindingFlags.NonPublic | BindingFlags.Instance);
					mi.Invoke(this.Page, null);
					//this.Page.RegisterEnabledControl(this);
				}
			}
		}

		protected override void PerformDataBinding(IEnumerable dataSource)
		{
			base.PerformDataBinding(dataSource);
			if (dataSource != null)
			{
				bool flag = false;
				bool flag2 = false;
				string dataTextField = this.DataTextField;
				string dataValueField = this.DataValueField;
				string dataTextFormatString = this.DataTextFormatString;
				if (!this.AppendDataBoundItems)
				{
					this.Items.Clear();
				}
				ICollection is2 = dataSource as ICollection;
				if (is2 != null)
				{
					this.Items.Capacity = is2.Count + this.Items.Count;
				}
				if ((dataTextField.Length != 0) || (dataValueField.Length != 0))
				{
					flag = true;
				}
				if (dataTextFormatString.Length != 0)
				{
					flag2 = true;
				}
				foreach (object obj2 in dataSource)
				{
					DatePickerListItem item = new DatePickerListItem();
					if (flag)
					{
						if (dataTextField.Length > 0)
						{
							item.Text = DataBinder.GetPropertyValue(obj2, dataTextField, dataTextFormatString);
						}
						if (dataValueField.Length > 0)
						{
							item.Value = DataBinder.GetPropertyValue(obj2, dataValueField, null);
						}
					}
					else
					{
						if (flag2)
						{
							item.Text = string.Format(CultureInfo.CurrentCulture, dataTextFormatString, new object[] { obj2 });
						}
						else
						{
							item.Text = obj2.ToString();
						}
						item.Value = obj2.ToString();
					}
					this.Items.Add(item);
				}
			}
			if (this.cachedSelectedValue != null)
			{
				int num = -1;
				num = this.Items.FindByValueInternal(this.cachedSelectedValue, true);
				if (-1 == num)
				{
					//throw new ArgumentOutOfRangeException("value", System.Web.SR.GetString("ListControl_SelectionOutOfRange", new object[] { this.ID, "SelectedValue" }));
					throw new ArgumentOutOfRangeException("List Control Selection Out Of Range Selected Value");
				}
				if ((this.cachedSelectedIndex != -1) && (this.cachedSelectedIndex != num))
				{
					//throw new ArgumentException(System.Web.SR.GetString("Attributes_mutually_exclusive", new object[] { "SelectedIndex", "SelectedValue" }));
					throw new ArgumentException("Attributes mutually exclusive Selected Index And Selected Value");
				}
				this.SelectedIndex = num;
				this.cachedSelectedValue = null;
				this.cachedSelectedIndex = -1;
			}
			else if (this.cachedSelectedIndex != -1)
			{
				this.SelectedIndex = this.cachedSelectedIndex;
				this.cachedSelectedIndex = -1;
			}
		}

		protected override void RenderContents(HtmlTextWriter writer)
		{
			DatePickerListItemCollection items = this.Items;
			int count = items.Count;
			if (count > 0)
			{
				bool flag = false;
				for (int i = 0; i < count; i++)
				{
					DatePickerListItem item = items[i];
					if (item.Enabled)
					{
						writer.WriteBeginTag("option");
						if (item.Selected)
						{
							if (flag)
							{
								//this.VerifyMultiSelect();
								//throw new HttpException(System.Web.SR.GetString("Cant_Multiselect", new object[] { "DropDownList" }));
								throw new HttpException("Cant Multiselect Drop Down List");
							}
							flag = true;
							writer.WriteAttribute("selected", "selected");
						}
						writer.WriteAttribute("value", item.Value, true);
						if (item.HasAttributes)
						{
							item.Attributes.Render(writer);
						}
						if (this.Page != null)
						{
							this.Page.ClientScript.RegisterForEventValidation(this.UniqueID, item.Value);
						}
						writer.Write('>');
						HttpUtility.HtmlEncode(item.Text, writer);
						writer.WriteEndTag("option");
						writer.WriteLine();
					}
				}
			}
		}

		/************************************************************************************************************/
		
		#region droplist

		/*
		protected override void AddAttributesToRender(HtmlTextWriter writer)
		{
			string uniqueID = this.UniqueID;
			if (uniqueID != null)
			{
				writer.AddAttribute(HtmlTextWriterAttribute.Name, uniqueID);
			}
			base.AddAttributesToRender(writer);
		}
		*/

		protected override ControlCollection CreateControlCollection()
		{
			return new EmptyControlCollection(this);
		}

		protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection)
		{
			string[] values = postCollection.GetValues(postDataKey);
			this.EnsureDataBound();
			if (values != null)
			{
				MethodInfo mi = this.GetType().GetMethod("ValidateEvent", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { typeof(string), typeof(string) }, null);
				mi.Invoke(this, new object[] { postDataKey, values[0] });
				//base.ValidateEvent(postDataKey, values[0]);
				int selectedIndex = this.Items.FindByValueInternal(values[0], false);
				if (this.SelectedIndex != selectedIndex)
				{
					this.SetPostDataSelection(selectedIndex);
					return true;
				}
			}
			return false;
		}

		protected virtual void RaisePostDataChangedEvent()
		{
			PropertyInfo pi = this.Page.GetType().GetProperty("IsPostBackEventControlRegistered", BindingFlags.NonPublic | BindingFlags.Instance, null, typeof(bool), new Type[0], null);
			if (this.AutoPostBack && !((bool)pi.GetValue(this.Page, null)))//this.Page.IsPostBackEventControlRegistered
			{
				pi = this.Page.GetType().GetProperty("AutoPostBackControl", BindingFlags.NonPublic | BindingFlags.Instance, null, typeof(Control), new Type[0], null);
				pi.SetValue(this.Page, this, null);
				//this.Page.AutoPostBackControl = this;
				if (this.CausesValidation)
					this.Page.Validate(this.ValidationGroup);
			}
			this.OnSelectedIndexChanged(EventArgs.Empty);
		}

		bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection)
		{
			return this.LoadPostData(postDataKey, postCollection);
		}

		void IPostBackDataHandler.RaisePostDataChangedEvent()
		{
			this.RaisePostDataChangedEvent();
		}

		/*
		protected internal override void VerifyMultiSelect()
		{
			throw new HttpException(System.Web.SR.GetString("Cant_Multiselect", new object[] { "DropDownList" }));
		}
		*/

		[Browsable(false)]
		public override Color BorderColor
		{
			get
			{
				return base.BorderColor;
			}
			set
			{
				base.BorderColor = value;
			}
		}

		[Browsable(false)]
		public override System.Web.UI.WebControls.BorderStyle BorderStyle
		{
			get
			{
				return base.BorderStyle;
			}
			set
			{
				base.BorderStyle = value;
			}
		}

		[Browsable(false)]
		public override Unit BorderWidth
		{
			get
			{
				return base.BorderWidth;
			}
			set
			{
				base.BorderWidth = value;
			}
		}

		/*
		//[WebCategory("Behavior")]
		//[WebSysDescription("WebControl_SelectedIndex")]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		[DefaultValue(0)]
		public override int SelectedIndex
		{
			get
			{
				int selectedIndex = base.SelectedIndex;
				if ((selectedIndex < 0) && (this.Items.Count > 0))
				{
					this.Items[0].Selected = true;
					selectedIndex = 0;
				}
				return selectedIndex;
			}
			set
			{
				base.SelectedIndex = value;
			}
		}
		*/

		/*
		internal override ArrayList SelectedIndicesInternal
		{
			get
			{
				int selectedIndex = this.SelectedIndex;
				return base.SelectedIndicesInternal;
			}
		}
		*/

		#endregion

	}
}

